import logging
import os
import time
import pytest

'''
logging模块配置日志记录器，设置日志级别、日志格式和日志输出位置
'''

current_path = os.getcwd()
base_path = os.path.dirname(os.path.dirname(current_path))
log_data_path = os.path.join(base_path,'log')
if not os.path.exists(log_data_path):
    os.mkdir(log_data_path)

def log_config():
    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s',
                        filename=f"{time.strftime('%Y-%m-%D',time.localtime())}pytest_automation.log",
                        filemode='w')
log_config()

class UseLogger:

    def __init__(self):
        self.logger=logging.getLogger(__name__)


# use_log=UseLogger()
#
# test_logger = TestLogger()
#
# # pytest钩子函数
# @pytest.hookimpl(tryfirst=True)
# def pytest_runtest_setup(item):
#     # 记录测试开始
#     test_logger.record_test_start(item.nodeid, item.callspec.id)
#
# @pytest.hookimpl(tryfirst=True)
# def pytest_runtest_teardown(item, nextitem):
#     # 记录测试结束和结果
#     if item.outcome.excinfo:
#         test_logger.error(f"Test failed: {item.nodeid}")
#     else:
#         test_logger.info(f"Test passed: {item.nodeid}")